﻿using DL;
using DL.Repositories;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace BusinessService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "CauHinhService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select CauHinhService.svc or CauHinhService.svc.cs at the Solution Explorer and start debugging.
    public class CauHinhService : ICauHinhService
    {
        public CauHinh ChiTietCauHinh()
        {
            try
            {
                var sanphamDataTier = new CauHinhRepository();
                var resultList = new CauHinh();
                var dataTable = sanphamDataTier.ChiTietCauHinh();
                if (dataTable != null && dataTable.Rows.Count == 1)
                {
                    foreach (DataRow dr in dataTable.Rows)
                    {
                        resultList.Id = Convert.ToInt64(dr["C_Id"]);
                        resultList.Text1 = dr["C_Text1"].ToString();
                        resultList.Text2 = dr["C_Text2"].ToString();
                        resultList.Text3 = dr["C_Text3"].ToString();
                        resultList.Text4 = dr["C_Text4"].ToString();
                        resultList.Image1 = dr["C_Image1"].ToString();
                        resultList.Image2 = dr["C_Image2"].ToString();
                        resultList.Text5 = dr["C_Text5"].ToString();
                    }

                }
                return resultList;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public List<Slide> DanhSachSlide()
        {
            try
            {
                var cauhinhDataTier = new CauHinhRepository();
                var resultList = new List<Slide>();
                var dataTable = cauhinhDataTier.DanhSachSlide();
                if (dataTable != null && dataTable.Rows.Count > 0)
                {
                    foreach (DataRow dr in dataTable.Rows)
                    {
                        var s = new Slide();
                        s.Id = Convert.ToInt64(dr["CHS_Id"]);
                        s.DuongDan = dr["CHS_Link"].ToString();
                        s.TrangThai = Convert.ToInt32(dr["CHS_TrangThai"]);
                        s.ThuTu = Convert.ToInt64(dr["CHS_ThuTu"]);
                        resultList.Add(s);
                    }

                }
                return resultList;
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        public string CapNhatSlide(Slide sl)
        {
            var cauhinhDataTier = new CauHinhRepository();
            var result = cauhinhDataTier.CapNhatSlide(sl);
            return result;
        }
        public string CapNhatCauHinh(CauHinh sl)
        {
            var cauhinhDataTier = new CauHinhRepository();
            var result = cauhinhDataTier.CapNhatCauHinh(sl);
            return result;
        }
    }
}
